import React 		from 'react';
import PageTitle 	from 'component/pagetitle/index.jsx';
import { Link } 	from 'react-router-dom';
import HomeService 	from 'service/home-service.jsx';
import MUtil        from 'util/mm.jsx';
import 					 './index.scss';

const _home 		= new HomeService();
const _util 		= new MUtil();
class Home extends React.Component{
	constructor(props){
		super(props)	
		this.state = {
			userCount: 0,
			productCount:0 ,
			orderCount: 0
		}
	}
	
	componentDidMount(){
		_home.getBaseCount()
			 .then(res => {
				 this.setState(res);
			 },errMsg =>{
				 _util.errorTips(errMsg);
			 });
	}
	
	render(){
		return (
			<div id="page-wrapper">
				<PageTitle title="首页" />
				<div className="row">
					<div className="col-md-4">
						<Link className="color-box brown" to="/user">
							<p className="count">{this.state.userCount}</p>
							<p className="desc">
								<i className="fa fa-user-o"></i>
								<span>用户总数</span>
							</p>
						</Link>
					</div>
					<div className="col-md-4">
						<Link className="color-box green" to="/product">
							<p className="count">{this.state.productCount}</p>
							<p className="desc">
								<i className="fa fa-list"></i>
								<span>商品总数</span>
							</p>
						</Link>
					</div>
					<div className="col-md-4">
						<Link className="color-box blue" to="/order">
							<p className="count">{this.state.orderCount}</p>
							<p className="desc">
								<i className="fa fa-check-square-o"></i>
								<span>订单总数</span>
							</p>
						</Link>
					</div>
				</div>
			</div>
		)
	}
}

export default Home;